namespace RegisterApp.WebUI.Migrations
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class InitialCreate : DbMigration
    {
        public override void Up()
        {
            CreateTable(
                "dbo.Account",
                c => new
                    {
                        UserId = c.Int(nullable: false, identity: true),
                        UserName = c.String(),
                        RegisterDate = c.DateTime(nullable: false),
                    })
                .PrimaryKey(t => t.UserId)
                .ForeignKey("dbo.Player", t => t.UserId)
                .Index(t => t.UserId);
            
            CreateTable(
                "dbo.Player",
                c => new
                    {
                        PlayerId = c.Int(nullable: false, identity: true),
                        FirstName = c.String(),
                        LastName = c.String(),
                        BirstDate = c.DateTime(nullable: false),
                    })
                .PrimaryKey(t => t.PlayerId);
            
            CreateTable(
                "dbo.Comment",
                c => new
                    {
                        CommentId = c.Int(nullable: false, identity: true),
                        CommentString = c.String(),
                        Match_MatchId = c.Int(),
                        Player_PlayerId = c.Int(),
                    })
                .PrimaryKey(t => t.CommentId)
                .ForeignKey("dbo.Match", t => t.Match_MatchId)
                .ForeignKey("dbo.Player", t => t.Player_PlayerId)
                .Index(t => t.Match_MatchId)
                .Index(t => t.Player_PlayerId);
            
            CreateTable(
                "dbo.Match",
                c => new
                    {
                        MatchId = c.Int(nullable: false, identity: true),
                        Name = c.String(),
                        Date = c.DateTime(nullable: false),
                        NumPlayer = c.Int(nullable: false),
                        Time = c.String(),
                        Info = c.String(),
                        Status = c.Boolean(nullable: false),
                        Stadium_StreetAddress = c.String(),
                        Stadium_City = c.String(),
                        Stadium_District = c.String(),
                    })
                .PrimaryKey(t => t.MatchId);
            
            CreateTable(
                "dbo.Team",
                c => new
                    {
                        TeamId = c.Int(nullable: false, identity: true),
                        Name = c.String(),
                        DateCreate = c.DateTime(nullable: false),
                        Match_MatchId = c.Int(),
                    })
                .PrimaryKey(t => t.TeamId)
                .ForeignKey("dbo.Match", t => t.Match_MatchId)
                .Index(t => t.Match_MatchId);
            
            CreateTable(
                "dbo.MatchPlayer",
                c => new
                    {
                        Match_MatchId = c.Int(nullable: false),
                        Player_PlayerId = c.Int(nullable: false),
                    })
                .PrimaryKey(t => new { t.Match_MatchId, t.Player_PlayerId })
                .ForeignKey("dbo.Match", t => t.Match_MatchId, cascadeDelete: true)
                .ForeignKey("dbo.Player", t => t.Player_PlayerId, cascadeDelete: true)
                .Index(t => t.Match_MatchId)
                .Index(t => t.Player_PlayerId);
            
            CreateTable(
                "dbo.TeamPlayer",
                c => new
                    {
                        Team_TeamId = c.Int(nullable: false),
                        Player_PlayerId = c.Int(nullable: false),
                    })
                .PrimaryKey(t => new { t.Team_TeamId, t.Player_PlayerId })
                .ForeignKey("dbo.Team", t => t.Team_TeamId, cascadeDelete: true)
                .ForeignKey("dbo.Player", t => t.Player_PlayerId, cascadeDelete: true)
                .Index(t => t.Team_TeamId)
                .Index(t => t.Player_PlayerId);
            
        }
        
        public override void Down()
        {
            DropForeignKey("dbo.Account", "UserId", "dbo.Player");
            DropForeignKey("dbo.Comment", "Player_PlayerId", "dbo.Player");
            DropForeignKey("dbo.TeamPlayer", "Player_PlayerId", "dbo.Player");
            DropForeignKey("dbo.TeamPlayer", "Team_TeamId", "dbo.Team");
            DropForeignKey("dbo.Team", "Match_MatchId", "dbo.Match");
            DropForeignKey("dbo.MatchPlayer", "Player_PlayerId", "dbo.Player");
            DropForeignKey("dbo.MatchPlayer", "Match_MatchId", "dbo.Match");
            DropForeignKey("dbo.Comment", "Match_MatchId", "dbo.Match");
            DropIndex("dbo.TeamPlayer", new[] { "Player_PlayerId" });
            DropIndex("dbo.TeamPlayer", new[] { "Team_TeamId" });
            DropIndex("dbo.MatchPlayer", new[] { "Player_PlayerId" });
            DropIndex("dbo.MatchPlayer", new[] { "Match_MatchId" });
            DropIndex("dbo.Team", new[] { "Match_MatchId" });
            DropIndex("dbo.Comment", new[] { "Player_PlayerId" });
            DropIndex("dbo.Comment", new[] { "Match_MatchId" });
            DropIndex("dbo.Account", new[] { "UserId" });
            DropTable("dbo.TeamPlayer");
            DropTable("dbo.MatchPlayer");
            DropTable("dbo.Team");
            DropTable("dbo.Match");
            DropTable("dbo.Comment");
            DropTable("dbo.Player");
            DropTable("dbo.Account");
        }
    }
}
